Repository navigation
Conversation
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #887 +/- ##
=========================================
Coverage 99.70% 99.71%
- Complexity 1952 1963 +11
=========================================
Files 146 146
Lines 4459 4497 +38
=========================================
+ Hits 4446 4484 +38
Misses 13 13 ☔ View full report in Codecov by Harness. |
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Firehed
added a commit
that referenced
this pull request
Oct 29, 2026
Which traits a class-like uses now has one answer, and it holds only
traits. `MemberResolver` turned every name written in `use` into a trait
edge, whatever that name turned out to be, and flattened its members
into the using class as the class's own. In code being edited `use`
often names a class, interface or enum, and its members, private ones
included, then counted as the using class's own. Alias resolution
separately read the written trait names itself and looked up whatever
class an alias named.
## Rules (php-src)
- `use` names only traits ("%s cannot use %s - it is not a trait",
`zend_do_link_class` in `Zend/zend_inheritance.c`).
- An `as` alias that names its trait draws only from a trait the class
uses ("Required Trait %s wasn't added to %s").
## Changes
- `MemberResolver::usedTraits()` is the one answer to which traits a
class-like uses, keeping only names that resolve to a trait. The walk
(`supertypes()`) and alias resolution (`findAliasSource()`) both read
it.
## Behavior
Only code PHP rejects changes: members of a class, interface or enum
named in `use` no longer appear on the class using it, and an alias
naming a trait the class does not use resolves to nothing.
## Not changed
A parent or interface of the wrong kind (`class C extends
SomeInterface`) is still followed. PHP rejects that declaration
outright, so there is no correct answer to match, and that class-like's
members stay attributed to it rather than to the class.
Alias resolution has no cycle guard of its own. A class using itself
with an alias used to recurse until PHP segfaulted; it no longer reaches
that path, which `MemberResolverTest` now pins. A trait using itself
with an alias still recurses without end. That is #889, kept as the
known-defect script `tests/EndToEnd/defects/889-trait-alias-cycle.php`
(ADR 0008).
## Why now
#887 resolves used traits as units, which showed that a class named in
`use`, including a class using itself, leaked that class's whole
hierarchy into the user. That PR is paused until this lands.
🤖 Generated with [Claude Code](https://claude.com/claude-code)
---------
Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
A trait's abstract method no longer hides a method the class gets elsewhere. PHP binds a class's used traits in two passes around inheritance (php-src
zend_do_link_class): concrete trait members before the class inherits from its parent, abstract trait methods after, and an abstract trait method only fills a name nothing else provides (zend_add_trait_method). The member resolver flattened every trait member ahead of the parent chain, so inC::sharedresolved toT's abstract method instead ofP's.Changes
MemberResolver::supertypes()lists a class's used traits twice: before the parent chain and after it, each tagged with aTraitBinding. Each trait is looked up once.traitMembers()): its own members win over those of traits it uses, as PHP composes a trait before it is used. Only then is each member assigned to a binding. So a trait whose own abstract method overrides a concrete one from a trait it uses still brings in an abstract method. Each trait is resolved once per walk, for the wanted name only.trait T { use T; }, or two traits using each other), which PHP rejects but code being edited can contain, brings in nothing more instead of recursing.MemberKind::bindsBeforeInheritance()says which members bind first: everything except abstract methods.Behavior
Hover, go to definition and signature help on such a method now show the inherited or concrete trait method rather than the abstract one; completion lists it once, as concrete.
Tests
MemberResolverTypeGraphTestgains a reflection check that every public method is abstract exactly when PHP says it is, over all its hierarchy fixtures, plus fixtures for: an abstract trait method beside a parent method, beside a concrete trait method, a trait whose own abstract method overrides a used trait, and an abstract trait method alone.MemberResolverTestadds a trait cycle and protected access from a sibling to a parent method that a used trait redeclares abstract.Same kind of trait-composition mismatch as the cases in #732; this one is not among those listed there. Two related cases already on
mainremain: anasalias of an abstract trait method overrides an inherited method, andinsteadofis applied to abstract methods, which PHP binds without exclusions. They belong with #732.🤖 Generated with Claude Code